import { defineConfig } from "vite";
import react from "@vitejs/plugin-react";
import path from "path";

// https://vitejs.dev/config/
export default defineConfig(({ command, mode }) => ({
  plugins: [
    react({
      babel: {
        plugins: [
          ["@babel/plugin-proposal-decorators", { legacy: true }],
          ["@babel/plugin-proposal-class-properties", { loose: true }],
        ],
      },
    }),
  ],
  resolve: {
    alias:
      // {
      //   "@": path.resolve(__dirname, "src"),
      // },

      [
        {
          find: "@",
          replacement: path.join(__dirname, "src"),
        },
        {
          find: "-",
          replacement: path.resolve(__dirname, "src"),
        },
      ],
  },
  // server: {
  //   proxy: {
  //     "/api": {
  //       target: "http://jsonplaceholder.typicode.com",
  //       // changeOrigin: true,
  //       // rewrite: (path) => path.replace(/^\/api/, ""),
  //       changeOrigin: true,
  //     },
  //   },
  // },
  server: {
    proxy: {
      "/staff": "https://ckmtest.gzyinfengkeji.com",
    },
  },
  /** 打包后后端的路径，找资源的路径 */
  base: command === "build" ? "/manage" : "/",
}));
